<template>
  <base-module
    class="tower-crane-comp"
    :title="title"
    @icon-click="handleClick"
    v-bind="$attrs"
    v-on="$listeners"
  >
    <video-play v-if="Object.keys(liveOptions).length" :data="liveOptions"></video-play>
  </base-module>
</template>

<script>
import BaseModule from '@/components/public/BaseModule';
import VideoPlay from '@/components/public/Video';

// 人员情况
export default {
  name: 'towerCraneComp',
  props: {
    title: {
      type: [String, Object],
      default: '视频监控'
    },
    data: {
      type: Array,
      default: () => ([])
    }
  },
  data() {
    return {
      // 直播信息
      liveOptions: {}
    };
  },
  computed: {
    projectName() {
      return this.$store.state.currentProjectInfo.projectName;
    }
  },
  mounted() {
    this.getLiveToken();
  },
  methods: {
    /**
     * 获取所有摄像机的信息
     */
    async getLiveToken() {
      try {
        const { success, data } = await this.$Model.getameraList({
          project_name: this.projectName
        });
        if (success && data.data) {
          const result = data.data.data || [];
          if (result[0]) {
            const { access_token, nums_device, passageway } = result[0];
            this.liveOptions = {
              accessToken: access_token,
              template: 'simple',
              url: `ezopen://open.ys7.com/${nums_device}/${passageway}.live`
            };
          }
        }
      } catch (e) {}
    },
    handleClick() {
      this.$router.push('/environment/surveillance');
    },
  },
  components: {
    VideoPlay,
    BaseModule
  }
};
</script>

<style lang="scss" scoped>
  .tower-crane-comp .video-comp {
    padding: 5px;
  }
</style>
